package com.season.seasonStudy.javase.j_021_io;
import java.io.File;

public class TestIO {
	public static void main(String[] args) {
		File file = new File("F:\\新建文件夹\\Hello.txt");
		File fil = new File("F:\\新建文件夹");
		// File file2=new File("F:\\新建文件夹\\Hello2.txt");
		// 判断是文件还是文件夹
		/*
		 * if(file.isFile()){ System.out.println("文件名是："+file.getName());
		 * System.out.println("所在文件夹是："+file.getParent());
		 * System.out.println("文件路径："+file.getPath());
		 * System.out.println("绝对路径："+file.getAbsolutePath());
		 * System.out.println("文件大小："+file.length()); }else
		 * if(file.isDirectory()){ System.out.println("文件夹的名字是"+file.getName());
		 * }
		 */
		// 判断文件不存在就新建文件
		/*
		 * if(!file2.exists()){ try { file2.createNewFile();
		 * System.out.println(file2.getName()); } catch (IOException e) {
		 * e.printStackTrace(); } }
		 */
		// 删除文件
		/*
		 * if(file2.delete()){ System.out.println("删除成功"); }
		 */
		// 查看同级文件或文件夹
		/*
		 * File[] fs =fil.listFiles(); for (File f : fs) {
		 * System.out.println(f.getName()); }
		 */
		
		//字节流
		/*FileInputStream in=null;
		FileOutputStream out=null;
		try {
			in = new FileInputStream(file);
			out=new FileOutputStream("F:\\新建文件夹\\e.txt",true);
			System.out.println(in.available());
			byte[] b=new byte[22];
			in.read(b);
			out.write(b);
			for (byte c : b) {
				System.out.print((char)c);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				in.close();
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}*/
		
		//字符流
		/*FileReader fr=null;
		BufferedReader br=null;
		FileWriter fw=null;
		BufferedWriter bw=null;
		try {
			fr=new FileReader(file);
			br=new BufferedReader(fr);
			fw=new FileWriter("F:\\新建文件夹\\e.txt",true);
			bw=new BufferedWriter(fw);
			char[] chars=new char[100];
			fr.read(chars);
			for (char c : chars) {
				System.out.print(c);
			}
			String a=br.readLine();
			System.out.println(a);
			bw.write(a);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				br.close();
				fr.close();
				bw.close();
				fw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}*/
		
		//读写二进制文件
		/*DataInputStream dis=null;
		DataOutputStream dos=null;
		InputStream in=null;
		OutputStream out=null;
		try {
			in=new FileInputStream("F:\\新建文件夹\\a.jpg");
			out=new FileOutputStream("F:\\新建文件夹\\a1.jpg");
			dis=new DataInputStream(in);
			dos=new DataOutputStream(out);
			int data;
			while(true){
				data=dis.read();
				if(data==-1){
					break;
				}
				dos.write(data);
			}
	
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				dis.close();
				in.close();
				dos.close();
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}*/
		
	}

}
